﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeProductByIDDataAction : BestLifeDataAction<DataTable>
    {
         private string Gvproductbarcode;
         private string Gvcatid;
         DataTable GvTable = new DataTable();

         public BestLifeProductByIDDataAction(string Pproductbarcode,string Pcatid)
        {
            Gvproductbarcode = Pproductbarcode;
            Gvcatid = Pcatid;
        }


         public override DataTable Body(SqlConnection PConn)
         {
            try
            {

                #region Datatable

                GvTable.Columns.Add("Pro_ID");
                GvTable.Columns.Add("Pl_Id");
                GvTable.Columns.Add("Brand_Name");
                GvTable.Columns.Add("Pro_Name");
                GvTable.Columns.Add("Pro_Price");
                GvTable.Columns.Add("Ret_Price");
                GvTable.Columns.Add("PV");
                GvTable.Columns.Add("BV");
                GvTable.Columns.Add("Quantity");


                #endregion

                List<string> LvList = new List<string>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetProductByBarcodeForPos";
                LvCommand.Parameters.Add(new SqlParameter("@Barcode_ID", Gvproductbarcode));//when passing parameters to the SP
                //LvCommand.Parameters.Add(new SqlParameter("@CatID", Gvproductid));//Pass Second Parameter
                
                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {

                 
                    GvTable.Rows.Add(GvTable.NewRow());

                    GvTable.Rows[GvTable.Rows.Count - 1][0] = LvReader.GetValue(0).ToString();
                    GvTable.Rows[GvTable.Rows.Count - 1][1] = LvReader.GetValue(1).ToString();
                    GvTable.Rows[GvTable.Rows.Count - 1][2] = LvReader.GetValue(2).ToString();
                    GvTable.Rows[GvTable.Rows.Count - 1][3] = LvReader.GetValue(3).ToString();
                    GvTable.Rows[GvTable.Rows.Count - 1][4] = LvReader.GetValue(4).ToString();
                    GvTable.Rows[GvTable.Rows.Count - 1][5] = LvReader.GetValue(5).ToString();
                    GvTable.Rows[GvTable.Rows.Count - 1][6] = LvReader.GetValue(6).ToString();
                    GvTable.Rows[GvTable.Rows.Count - 1][7] = LvReader.GetValue(6).ToString();
                    GvTable.Rows[GvTable.Rows.Count - 1][8] = "1";
                  

                  
                }
                return GvTable;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }

    }
}
